import { extract as extractInfo , classify as classifyInfo } from '../services/parser';

export default {
  namespace: 'parser',

  state: {
    tagResult: [],
    typeResult: {
      'lv1_tag_list': [],
      'lv2_tag_list': [],
    },
  },

  effects: {
    *parse({ payload }, { call, put }){
      const tagResponse = yield call(extractInfo, payload);
      const typeResponse = yield call(classifyInfo, payload);
      yield put({
        type: 'loadResult',
        payload: {
          tagResult: tagResponse.data,
          typeResult: typeResponse.data,
        },
      });
    },
  },

  reducers: {
    loadResult(state, action){
      return {
        ...state,
        tagResult: action.payload.tagResult,
        typeResult: action.payload.typeResult,
      }
    },
  },
};
